import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
url = "https://www.douban.com"
driver.get(url)

# elem = driver.find_element('id', 'kw')
# # 输入京东
# elem.send_keys("京东")
# elem.submit()
# driver.find_element(By.CLASS_NAME, 'tenon_pc_comp_wrapper').click()
# print(driver.title)
# driver.quit()

driver.find_element(By.XPATH, "//a[@class='lnk-book']").click()

#打印所有句柄
print(driver.window_handles)
# 切换窗口，参数为句柄的最后一个，这里的参数是索引0123456
driver.switch_to.window(driver.window_handles[1])
time.sleep(2)
print(driver.title)
driver.quit()
